package hadoop.mapreduce.partitionsort;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 *外部排序
 */
public class MyWritableComparator extends WritableComparator {

    //指定当前比较器以什么(PhoneBean)作比较
    public MyWritableComparator() {
        super(PhoneBean.class,true);
    }

    /**
     *
     * @param a
     * @param b
     * @return 第一个和第二个比较,-1不换位置,1换位置,0不处理
     */
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        PhoneBean beanA=(PhoneBean)a;
        PhoneBean beanB=(PhoneBean)b;
        int result=0;
        // 按照总流量大小，升序排列
        if (beanA.getSumFlow() > beanB.getSumFlow()) {
            result = 1;
        }else if (beanA.getSumFlow() < beanB.getSumFlow()) {
            result = -1;
        }
        return result;
    }
}
